package com.example.foobar.controller;

import com.example.foobar.business.service.DidiCompanyService;
import com.example.foobar.entity.DidiCompany;
import com.example.foobar.dao.service.DidiCompanyDaoService;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DidiCompanyPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 公司 控制器
 *
 * @author 郑英奔
 * @since 2021-11-16
 */
@Slf4j
@RestController
@RequestMapping("/didiCompany")
@Module("foobar")
@Api(value = "公司API", tags = {"公司"})
public class DidiCompanyController extends BaseController {

    @Autowired
    private DidiCompanyService didiCompanyService;

    /**
     * 添加公司
     */
    @PostMapping("/add")
    @OperationLog(name = "添加公司", type = OperationLogType.ADD)
    @ApiOperation(value = "添加公司", response = ApiResult.class)
    public ApiResult<Boolean> addDidiCompany(@Validated(Add.class) @RequestBody DidiCompany didiCompany) throws Exception {
        boolean flag = didiCompanyService.saveDidiCompany(didiCompany);
        return ApiResult.result(flag);
    }

    /**
     * 修改公司
     */
    @PostMapping("/update")
    @OperationLog(name = "修改公司", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改公司", response = ApiResult.class)
    public ApiResult<Boolean> updateDidiCompany(@Validated(Update.class) @RequestBody DidiCompany didiCompany) throws Exception {
        boolean flag = didiCompanyService.updateDidiCompany(didiCompany);
        return ApiResult.result(flag);
    }

    /**
     * 删除公司
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除公司", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除公司", response = ApiResult.class)
    public ApiResult<Boolean> deleteDidiCompany(@PathVariable("id") Long id) throws Exception {
        boolean flag = didiCompanyService.deleteDidiCompany(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取公司详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "公司详情", type = OperationLogType.INFO)
    @ApiOperation(value = "公司详情", response = DidiCompany.class)
    public ApiResult<DidiCompany> getDidiCompany(@PathVariable("id") Long id) throws Exception {
        DidiCompany didiCompany = didiCompanyService.getById(id);
        return ApiResult.ok(didiCompany);
    }

    /**
     * 公司分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "公司分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "公司分页列表", response = DidiCompany.class)
    public ApiResult<Paging<DidiCompany>> getDidiCompanyPageList(@Validated @RequestBody DidiCompanyPageParam didiCompanyPageParam) throws Exception {
        Paging<DidiCompany> paging = didiCompanyService.getDidiCompanyPageList(didiCompanyPageParam);
        return ApiResult.ok(paging);
    }

}

